﻿using System;

class LettersIndex
{
    static void Main()
    {
        //Exercise 12.
        //Write a program that creates an array containing all letters from the alphabet (A-Z). Read a word from the console and 
        //print the index of each of its letters in the array.

        Console.Write("Type a word: ");        
        string word = Console.ReadLine();
        int index = -1;

        foreach (char ch in word)
        {
            index = (int)ch - (int)'A';
            Console.WriteLine("Letter {0} - Index {1}", ch, index);
        }

        Console.WriteLine(new string('-',20));

        // here is another way to solve it
        int[] alphabet = new int[58];
        for (int i = 0; i < 26; i++)    //upper case
        {
            alphabet[i] = 'A' + i;            
        }
        for (int i = 32, m = 0; i < alphabet.Length; i++, m++)  //lower case; 
        {
            alphabet[i] = 'a' + m;                 //there are 6 zero-positions (between 26 & 31) in the array to match the numbers under ASCII
        }
                
        for (int p = 0; p < word.Length; p++)
        {
            for (int i = 0; i < alphabet.Length; i++)
            {
                if (word[p] == alphabet[i])
                {
                    Console.WriteLine("Letter {0} - Index {1}", word[p], i);
                }
            }
        }
        
    }
}

